/**
 * @author Zvonimir Pavlić
 */


function parseStockData(stockData){
	var innerDataRegex = new RegExp("<m([0-9]+):([0-9]+)[^>]*>([^<]+)</m>", "ig"); //checks for GYROS data format
	if (stockData.match(innerDataRegex) == null) {
		return null;
	}
	data = RegExp.$3;
	data = data.toString();
	columns = RegExp.$2;
	
	var AOPRegex = new RegExp(".*?AOP[^|]*.(.*)", "ig");
	
	data.match(AOPRegex);
	
	alignedData = RegExp.$1; //now we now that AOP numbers are at intervals specified by columns number (if columns=4
	//by skipping 4 items at a time we will surely hit the next number in sequence eventually
	
	
	var elementsToSkip = (columns - 1).toString();
	var skipRowRegex = new RegExp("([^|]*.){" + elementsToSkip + "}([^|]*).(.*)", "i"); //this one will remove one row from the data table
	var firstElementRegex = new RegExp("^([^|]*)", "i")
	
	nextAOP = 1;
	var aopString = "<br>";
	while (alignedData != "") {
		alignedData.match(skipRowRegex);
		
		currentAOP = RegExp.$2; //will be either an AOP neumber (relevant) or simething else (irelevant)
		dataBehindAOP = RegExp.$3;
		
		if (currentAOP == nextAOP) //if we hit the next AOP number in sequence, we need to memorise the first cell to the right of it
		{
			dataBehindAOP.match(firstElementRegex);
			currentAOPData = RegExp.$1;
			aopString += currentAOPData + "|";
			nextAOP++;
		}
		
		alignedData = dataBehindAOP;
		
	}
	
	return aopString;
	//AOP = aopString.split("|");
}

function ujna()
{
}

function Glavni(parametar)
{
	var ulaz = document.getElementById("ulaz");
	var izlaz = document.getElementById("izlaz");
	var tekst = new String(ulaz.value);
	var AOP = new Array;
	
	var aopTekst = new String(parseStockData(tekst));
	
	AOP = aopTekst.split("|");
	
	izlaz.value = tekst;
	var odjeljak = document.getElementById("odjeljak");
	

}
